"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SocketConnectionManager = void 0;
class SocketConnectionManager {
    constructor() {
        this.socketConnMap = new Map();
    }
    /*
   增加客户端socket连接
    */
    addSocketConnection(conn) {
        this.socketConnMap.set(conn.id, conn);
    }
    getSocketConnection(id) {
        return this.socketConnMap.get(id);
    }
    getSocketConnectionByUser(account) {
        let result = [];
        this.socketConnMap.forEach((conn, key) => {
            if (!conn.isClosing && conn.account && conn.account == account) {
                result.push(conn);
                return;
            }
        });
        return result;
    }
    /*
    删除客户端socket连接
     */
    removeSocketConnection(removeOne) {
        if (!removeOne) {
            return;
        }
        this.socketConnMap.delete(removeOne.id);
    }
    getConnectionCount() {
        let count = 0;
        this.socketConnMap.forEach((conn, key) => {
            if (conn.isLogin()) {
                // if(conn.user){
                //     count++
                // }
                // Logger.log("getConnectionCount==", conn.account, conn.user)
            }
        });
        return count;
    }
    getClubOnlineCount(clubid) {
        let count = 0;
        SocketConnectionManager.instance.socketConnMap.forEach((conn, key) => {
            if (conn.isLogin()) {
                // if (conn.user) {
                //     for (let i = 0; i < conn.user.clubList.length; i++) {
                //         let club: ClubModel = conn.user.clubList[i];
                //         if (club.clubid == clubid) {
                //             count++;
                //             break;
                //         }
                //     }
                // }
            }
        });
        return count;
    }
    isUserOnline(userid) {
        let isOnline = false;
        SocketConnectionManager.instance.socketConnMap.forEach((conn, key) => {
            if (conn.isLogin()) {
                // if (conn.user && conn.user.userid == userid) {
                //     isOnline = true
                //     return;
                // }
            }
        });
        return isOnline;
    }
    getSocketConnectionByUserid(userid) {
        let connection = null;
        this.socketConnMap.forEach((conn, key) => {
            if (conn.isLogin()) {
                // if (conn.user && conn.user.userid == userid) {
                //     connection = conn
                //     return conn;
                // }
            }
        });
        return connection;
    }
}
exports.SocketConnectionManager = SocketConnectionManager;
SocketConnectionManager.instance = new SocketConnectionManager();
